import Vue from 'vue'
import App from './App.vue'
import router from '@/router'

import Vant from 'vant'

import 'vant/lib/index.css'

Vue.use(Vant)

// 步骤一：引入SDK
import dhtrack from '@/utils/dhtrack_h5.js'
let is_new = 0;
if (!localStorage.getItem('dhh5_track_isNew')) {
    is_new = 1;
    localStorage.setItem('dhh5_track_isNew', 1);
} else {
    is_new = localStorage.getItem('dhh5_track_isNew');
    localStorage.setItem('dhh5_track_isNew', 0);
}
// 步骤二：创建埋点应用
dhtrack.setParams({
        tenantId: 'TEST', // 企业id
        appId: 'TEST', // 应用id
        terminal: 'H5' // 终端id
    }).init({
        serveUrl: 'https://demobank.szdinghui.com/testbank', //上报地址
        publicKey: '044448c4feb37de2589455c04e7d434ae3ba0ce134f5d31c037715493991ea45e3ce5c8e3fbc6e13f4b5f51f883574ff2dcc5b6a4693e3ac2c2aa6cfcfc01bdece', // 加密秘钥
        privateKey: '1c03f7492792ad6c0d740e8bd9dc49101b4dbee92dac548530ca3d707ec17338',
        debugger: true, // 是否开启调试模式
    })
    // 步骤三：全局暴露dhtrack
Vue.prototype.$dhtrack = dhtrack


router.beforeEach((to, from, next) => {
    // #region      viewPage埋点开始
    if (from.name) {
        let newTime = new Date().getTime();
        let duringTime = newTime - sessionStorage.getItem('track_entryTime');
        dhtrack.trackEvent("viewPage", {
            // 页面名称
            title: from.meta.title,
            // 当前页面路径
            url: from.path,
            // 原路径-要返回的页面路径
            oldPage: sessionStorage.getItem('track_oldPage'),
            // 页面停留时长
            duringTime
        });
        // 保存当前页面的上一个页面信息
        sessionStorage.setItem('track_oldPage', from.path)
    }
    //#endregion    viewPage埋点结束
    next()
})

new Vue({
    router,
    render: h => h(App)
}).$mount('#app')

// Vue.config.errorHandler = function(err, vm, info) {
//     console.log(err);
// }